# Maintainer: Andy Gross <andy.gross@linaro.org>

pkgname=dtc
pkgver=1.5.1
pkgrel=1
pkgdesc="Device Tree Compiler"
arch=('i686' 'x86_64')
url="https://git.kernel.org/pub/scm/utils/dtc/dtc/git"
license=('GPL2')
groups=('base')
makedepends=('python2' 'swig' 'libcrypt-devel')
source=("https://git.kernel.org/pub/scm/utils/dtc/dtc.git/snapshot/${pkgname}-${pkgver}.tar.gz"
        01-correct-shared-library-extension.patch
        02-pyext-install.patch)
sha256sums=('45f9885f890c5feab8110a721410970deb8f83987d0125f1a2703bc8ec140e33'
            'c563bf4d7cfc639bb5b902f35f9e7cb1e5d0828ee48004a149489a0a479eb4e2'
            '0135724ce6f5a30a381d2097bc6afa561168bdc16c42608fcc34c3990fa5b990')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  sed -i 's/python\b/python2/' tests/run_tests.sh

  # to make check work
  sed -i 's/__attribute__((weak))//' tests/testutils.c
  sed -i 's|#include <valgrind/|//#include <valgrind/|' tests/testutils.c
  sed -i 's|VALGRIND_|//VALGRIND_|' tests/testutils.c
  patch -p1 -i "${srcdir}/01-correct-shared-library-extension.patch"
  patch -p1 -i "${srcdir}/02-pyext-install.patch"
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make check
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make PREFIX=/usr DESTDIR="${pkgdir}" install

  # license
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/README.license ${pkgdir}/usr/share/licenses/${pkgname}/README.license
}

